#include "ufclt.h"
#include <fstream>
#include <iostream>
using namespace std;
UfClt::UfClt()
{

}

void UfClt::init(const char * fname, int algType)
{
    ifstream in(fname);

    int total = 0;
    in >> total;


    int v1 = 0, v2 = 0;

    while(in >> v1)
    {
        in >> v2;
        sites.push_back(make_pair(v1,v2));
    }

    switch (algType) {
    case type::QUICKFIND:
        uf = new QuickFind(total);
        break;
    default:
        break;
    }

}

void UfClt::run()
{
    for(int i = 0; i < sites.size(); ++i)
    {
        SitesPair &thePair = sites[i];
        if(!uf->isConnected(thePair.first,thePair.second))
        {
            std::cout << "union" << thePair.first << " " << thePair.second << std::endl;
            uf->unionSites(thePair.first,thePair.second);
        }
    }
    cout << "finally got " << uf->componentCount() <<   " components" << endl;

}
